const express = require("express");

const router = express.Router();

const cookiesession = require("cookie-session");

const path = require("path");

router.get("/register",(req,res)=>{
    res.sendFile(path.join(__dirname,"register.html"));
})
//使用中间件
router.use(cookiesession({
    name:"curuser",
    keys:["ckojbu(&&T^&^%%","ncjaufguicb*&&^%%"]
}))
//接收表单数据
router.post("/toregister",(req,res)=>{
    let {tel,pass,pass2} = req.body;
    var tipinfo = "";
     if(tel == "" || pass == "" || pass2 == "")
     {
         tipinfo = "不得为空";
     }
     else if(pass != pass2)
     {
        tipinfo = "两次输入密码不一致";
     }
     else
     {
       req.session.TEL = tel;
       req.session.PASS = pass;
       console.log(req.session);
       res.send("<script>alert('注册成功');location.href='/login';</script>")
     }
     res.render("tips.html",{tipinfo});

})
module.exports = router;